<template>
  <div class="login">
    <el-card header="登陆页面">
      <el-form>
        <el-form-item label="用户名">
          <el-input
            v-model="form.username"
            @keyup.enter.native="onSubmit"
          ></el-input>
        </el-form-item>
        <el-form-item label="密码">
          <el-input
            v-model="form.password"
            @keyup.enter.native="onSubmit"
          ></el-input>
        </el-form-item>
        <el-form-item>
          <el-button @click="onSubmit">登陆</el-button>
        </el-form-item>
      </el-form>
    </el-card>
  </div>
</template>

<script>
export default {
  data() {
    return {
      form: {
        username: "",
        password: "",
      },
    };
  },
  methods: {
    async onSubmit() {
      console.log("submit!");
      const res = await this.$http.post("login", this.form);
      if (res.data.token) {
        sessionStorage.token = res.data.token
        this.$message({
          type: "success",
          message: "登陆成功",
        });
        this.$router.push("/heroes/create");
      }
    },
  },
  created() {},
  mounted() {},
};
</script>

<style lang="css" scoped>
.login {
  width: 50%;
  margin: 10% auto;
}
</style>